package global

import (
	"hcy-api/structs/tables"
	"time"
)

func initCoursewareFolderRoot() {
	m := tables.CoursewareFolder{
		FolderId: 1,
		Name:     "全部",
		Describe: "系统定义的根目录",
		ParentId: 0,
		Sort:     1,
		AutoCreateInfo: tables.AutoCreateInfo{
			Creator:   "root",
			CreatorId: 1,
			CreatedAt: time.Now().Unix(),
			UpdatedAt: 0,
			DeletedAt: 0,
		},
	}
	var num int64
	if err := DB.Model(&tables.CoursewareFolder{}).Where(&tables.CoursewareFolder{FolderId: m.FolderId}).Count(&num).Error; err != nil {
		LmsLog.Error(err)
		return
	}
	if num == 0 {
		if err := DB.Create(&m).Error; err != nil {
			LmsLog.Error(err)
			return
		}
	}
}

func initCourseFolderRoot() {
	m := tables.CourseFolder{
		FolderId: 1,
		Name:     "全部",
		Describe: "系统定义的根目录",
		ParentId: 0,
		Sort:     1,
		AutoCreateInfo: tables.AutoCreateInfo{
			Creator:   "root",
			CreatorId: 1,
			CreatedAt: time.Now().Unix(),
			UpdatedAt: 0,
			DeletedAt: 0,
		},
	}
	var num int64
	if err := DB.Model(&tables.CourseFolder{}).Where(&tables.CourseFolder{FolderId: m.FolderId}).Count(&num).Error; err != nil {
		LmsLog.Error(err)
		return
	}
	if num == 0 {
		if err := DB.Create(&m).Error; err != nil {
			LmsLog.Error(err)
			return
		}
	}
}
